package com.nhtrinh.game;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

import com.nhtrinh.lib.CustomFont;
import com.nhtrinh.sound.BackgroundMusic;
import com.nhtrinh.sound.SoundEffect;

public class MenuActivity extends Activity implements OnClickListener{

	BackgroundMusic backgroundMusic;
	Button btnPlay;
	Button btnExit;
	Button btnScore;
	Button btnHelp;
	
	SoundEffect mSoundEffect;
	Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		backgroundMusic = new BackgroundMusic();
		backgroundMusic.execute(new Context[]{this});
		
		
		btnPlay = (Button)findViewById(R.id.activity_menu_btn_play);
		btnExit = (Button)findViewById(R.id.activity_menu_btn_exit);
		btnScore = (Button)findViewById(R.id.activity_menu_btn_score);
		btnHelp = (Button)findViewById(R.id.activity_menu_btn_help);
		
		btnPlay.setOnClickListener(this);
		btnExit.setOnClickListener(this);
		btnScore.setOnClickListener(this);
		btnHelp.setOnClickListener(this);
		
		
		
		mContext = MenuActivity.this;
		mSoundEffect = new SoundEffect(mContext);
		
		CustomFont mCustomFont = new CustomFont(mContext);
		Typeface tf = mCustomFont.loadCustomFont();
		
		btnPlay.setTypeface(tf);
		btnExit.setTypeface(tf);
		btnScore.setTypeface(tf);
		btnHelp.setTypeface(tf);
		
	}
	
	
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}




	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.activity_menu_btn_play:
			
			mSoundEffect.play(Constant.SOUND_EFFECT_PLAY);
			startActivity(new Intent(mContext, GameActivity.class));
			
			break;
			
		case R.id.activity_menu_btn_help:
			
			mSoundEffect.play(Constant.SOUND_EFFECT_PLAY);
			startActivity(new Intent(mContext, HelpActivity.class));
			break;
			
		case R.id.activity_menu_btn_exit:
			
			mSoundEffect.play(Constant.SOUND_EFFECT_PLAY);
			moveTaskToBack(true);
			break;
			
		case R.id.activity_menu_btn_score:
			
			mSoundEffect.play(Constant.SOUND_EFFECT_PLAY);
			startActivity(new Intent(mContext, ScoreActivity.class));
			break;

		default:
			break;
		}
	}


}
